<?php
class RegisterAction extends Action {
    public function index(){
    		$this->display();
    }
    
    function add(){
    		if(!empty($_POST['name'])){
    			$data['name']=$_POST['name'];
    			$data['username']=$_POST['username'];
    			$data['pwd']=$_POST['pwd'];
    			$data['phone']=$_POST['phone'];
    			
	    		$users = M("users");
	    		$res= $users->add($data);
	    		if($res){
	    			$info["info"] = "注册成功";
		    		$info['status']=1;
		    		session("username",$_POST['username']);
	    		}else{
	    			$info["info"] = "系统错误";
	    			$info['status']=2;
	    		}
    		}else{
    			$info["info"] = "数据不能为空";
    			$info['status']=3;
    		}
    		$this->ajaxReturn($info);
    }
    
    function checkusername(){
    		$data['username']=$_POST['username'];
    		$users = M("users");
    		$res=$users->where($data)->select(); 
    		if($res){
    			$info["info"] = "不可用";
	    		$info['status']=2;
    		}else{
    			$info["info"] = "可以用";
    			$info['status']=1;
    		}
    		$this->ajaxReturn($info);
    }
    
    public function getshopcar(){
    		$person['username'] = $_SESSION['username'];
    		$users = M("users");
    		$data = $users->where($person)->find();
    		$shopcar['userid'] = $data['id'];
    		$shopcart = M("shopcar");
    		$res = $shopcart->where($shopcar)->select();
    		if($res){
    			for($i = 0;$i<count($res);$i++){
	    			$goods = M("good");
	    			$good['id']=$res[$i]['goodid'];
	    			$goodinfo=$goods->where($good)->find();
		    		$goodinfo["imgurl"]=explode(',',$goodinfo["imgurl"])[0];
		    		$goodinfo["goodtype"] = $res[$i]['type'];
	    			$info['goodinfo'][$i]=$goodinfo;
	    		}
    			$info['data']=$res;
    			$info['count']=$res[0]['goodid'];
    			$info['status']=1;
    		}else{
    			$info['data']="";
    			$info['status']=2;
    		}
    		$this->ajaxReturn($info);
    }
    
    
    
}
?>